{% extends "pretixcontrol/event/settings_base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load hierarkey_form %}
{% load static %}
{% block inside %}
    <nav id="event-nav" class="header-nav">
        <div class="navigation">
            <div class="navigation-title">
                <h1>{% trans "E-mail settings" %}</h1>
            </div>
            {% include "pretixcontrol/event/component_link.html" %}
        </div>
    </nav>
    <form action="" method="post" class="form-horizontal" enctype="multipart/form-data"
            mail-preview-url="{% url "control:event.settings.mail.preview" event=request.event.slug organizer=request.event.organizer.slug %}">
        {% csrf_token %}
        {% bootstrap_form_errors form %}
        <div class="tabbed-form">
            <fieldset>
                <legend>{% trans "General" %}</legend>
                {% bootstrap_field form.mail_prefix layout="control" %}
                {% bootstrap_field form.mail_from layout="control" %}
                {% bootstrap_field form.mail_from_name layout="control" %}
                {% bootstrap_field form.mail_text_signature layout="control" %}
                {% bootstrap_field form.mail_bcc layout="control" %}
                {% bootstrap_field form.mail_attach_tickets layout="control" %}
                {% bootstrap_field form.mail_attach_ical layout="control" %}
                {% bootstrap_field form.mail_sales_channel_placed_paid layout="control" %}
            </fieldset>
            <fieldset>
                <legend>{% trans "E-mail design" %}</legend>
                <div class="row">
                    {% for r in renderers.values %}
                        <div class="col-md-3">
                            <div class="well maildesignpreview text-center">
                                <label class="radio">
                                    <input type="radio" name="mail_html_renderer" value="{{ r.identifier }}"
                                            {% if request.event.settings.mail_html_renderer == r.identifier %}checked{% endif %}>
                                    {{ r.verbose_name }}
                                </label>
                                <img src="{% static r.thumbnail_filename %}">
                                <a class="btn btn-default btn-sm" target="_blank"
                                        href="{% url "control:event.settings.mail.preview.layout" event=request.event.slug organizer=request.event.organizer.slug %}?renderer={{ r.identifier }}">
                                    {% trans "Preview" %}
                                </a>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            </fieldset>
            <fieldset>
                <legend>{% trans "Email settings" %}</legend>     
                {% bootstrap_field form.smtp_use_custom layout="control" %}
                {% bootstrap_field form.email_vendor layout="control" %}
                {% bootstrap_field form.send_grid_api_key layout="control" %} 
                {% bootstrap_field form.smtp_host layout="control" %}
                {% bootstrap_field form.smtp_port layout="control" %}
                {% bootstrap_field form.smtp_username layout="control" %}
                {% bootstrap_field form.smtp_password layout="control" %}
                {% bootstrap_field form.smtp_use_tls layout="control" %}
                {% bootstrap_field form.smtp_use_ssl layout="control" %}
            </fieldset>
        </div>
        <div class="form-group submit-group">
            <button type="submit" class="btn btn-primary btn-save">
                {% trans "Save" %}
            </button>
            <button type="submit" class="btn btn-default btn-save pull-left" name="test" value="1">
                {% trans "Save and test custom SMTP connection" %}
            </button>
        </div>
    </form>
{% endblock %}
